﻿using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace Editor.Utilities
{
    public static class XMLWorker<T>
    {
        public static void SerializeToXML(T obj, string fileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            TextWriter textWriter = new StreamWriter(fileName, false, Encoding.UTF8);

            serializer.Serialize(textWriter, obj);
            textWriter.Close();
        }

        public static T DeserializeFromXML(string fileName)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(T));
            TextReader textReader = new StreamReader(fileName, Encoding.UTF8);
            T content;

            content = (T) deserializer.Deserialize(textReader);
            textReader.Close();

            return content;
        }
    }
}
